package com.huabo.fxgl.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huabo.fxgl.entity.RiskAssplan;
import com.huabo.fxgl.entity.RiskAssplanRisk;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author LiYe
 * @since 2022-08-01
 */
@Repository
public interface RiskAssplanRiskMapper extends BaseMapper<RiskAssplanRisk> {
    /**
     * 查找风险类型
     * @author wanghongtuo
     * @Date 2022/8/10
     * @param typeId
     * @param planId
     * @return
     */
    @Select("select R.*" +
            " from TBL_RISK_ASSPLAN_RISK R LEFT JOIN TBL_RISK TR on TR.RISKID = R.RISKID" +
            " LEFT JOIN TBL_RISKCATEGORY T on TR.RISKCATID = T.RISKCATID" +
            " LEFT JOIN TBL_RISK_ASSPLAN TRA ON TRA.ASSPLANID=R.ASSPLANID" +
            " WHERE T.RISKCATID in (${param1}) and TRA.ASSPLANID = #{param2}")
    @ResultMap("RM_RISK_ASSPLAN_RISK")
    List<RiskAssplanRisk> findRiskByRiskType(String typeId, BigDecimal planId);

    @Select("select R.*" +
            "    from TBL_RISK_ASSPLAN_RISK R LEFT JOIN TBL_RISK_ASSPLAN TRA on R.ASSPLANID = TRA.ASSPLANID" +
            "        LEFT JOIN TBL_RISK TR on TR.RISKID = R.RISKID" +
            "    WHERE TRA.ASSPLANID = #{param2} and R.RISKID IN (${param1})")
    @ResultMap("RM_RISK_ASSPLAN_RISK")
    IPage<RiskAssplanRisk> findRiskInRiskIdAndAssId(String ids, BigDecimal planId, IPage pageBean);





}
